
package sr.codemg.controller;

import sr.codemg.config.JwtConfig;
import sr.codemg.entity.SrGroupMember;
import sr.codemg.utils.Constants;
import sr.codemg.vm.Base;
import sr.codemg.vm.Tables;
import sr.codemg.vm.Selects;
import sr.codemg.service.SrGroupMemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 我的团队
 **/
@Slf4j
@RestController
@RequestMapping("/srgroupmember")
public class SrGroupMemberController {

    @Autowired
    SrGroupMemberService srGroupMemberService;

    @GetMapping("/{id}")
    public SrGroupMember get(@PathVariable("id") String id) {
        return srGroupMemberService.get(id);
    }

    @PutMapping
    public Tables list(@RequestBody Map<String, Object> params, @CookieValue(Constants.Authorization) String token) {
        params.put("crtOpr", JwtConfig.getUserId(token));
        return srGroupMemberService.findList(params);
    }

    @PostMapping
    public Base.Response post(@RequestBody SrGroupMember entity, @CookieValue(Constants.Authorization) String token) {
        entity.setId(null);
        entity.setCrtOpr(JwtConfig.getUserId(token));
        return srGroupMemberService.add(entity);
    }

    @PutMapping("/edit")
    public Base.Response put(@RequestBody SrGroupMember entity) {
        return srGroupMemberService.update(entity);
    }

    @DeleteMapping("/{id}")
    public Base.Response delete(@PathVariable("id") String id) {
        return srGroupMemberService.delete(id);
    }

    @PostMapping("/select")
    public Selects.Response select(@RequestBody Selects.Request req, @CookieValue(Constants.Authorization) String token) {
        req.setP1(JwtConfig.getUserId(token));
        return srGroupMemberService.select(req);
    }
}

